using System;
using System.Linq.Expressions;
using PropertyExpression.ControllableQuery.TypedReader;

namespace PropertyExpression.ControllableQuery.Test
{
    public static class TupleDataReaderExtensions
    {
        private static class Properties<T1, T2, T3>
        {
            internal static readonly Expression<Func<Tuple<T1, T2, T3>, T1>> Item1 = _ => _.Item1;
            internal static readonly Expression<Func<Tuple<T1, T2, T3>, T2>> Item2 = _ => _.Item2;
            internal static readonly Expression<Func<Tuple<T1, T2, T3>, T3>> Item3 = _ => _.Item3;            
        }

        public static Guid Item1<T2, T3>(this IDataReader<Tuple<Guid, T2, T3>> it)
        {
            return it.GetValue(Properties<Guid, T2, T3>.Item1);
        }

        public static NVarChar<L20> Item2<T1, T3>(this IDataReader<Tuple<T1, NVarChar<L20>, T3>> it)
        {
            return it.GetValue(Properties<T1, NVarChar<L20>, T3>.Item2);
        }

        public static NVarChar<L2> Item3<T1, T2>(this IDataReader<Tuple<T1, T2, NVarChar<L2>>> it)
        {
            return it.GetValue(Properties<T1, T2, NVarChar<L2>>.Item3);
        }
    }

    public class Tuple<T1, T2, T3>
    {
        private readonly T1 item1;
        private readonly T2 item2;
        private readonly T3 item3;

        public T1 Item1
        {
            get { return item1; }
        }

        public T2 Item2
        {
            get { return item2; }
        }

        public T3 Item3
        {
            get { return item3; }
        }

        public Tuple(T1 item1, T2 item2, T3 item3)
        {
            this.item1 = item1;
            this.item2 = item2;
            this.item3 = item3;
        }
    }
}